package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import news.dao.impl.*;
import news.entity.*;

public class showNews extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public showNews() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int nid = Integer.parseInt(request.getParameter("nid"));
		NewsDaoImpl bews = new NewsDaoImpl();
		News news = null;
		news = bews.getNewsById(nid);
		CommentDaoImpl bb = new CommentDaoImpl();
		List<Comment> comments = bb.getCommentByCnid(nid);
		request.setAttribute("list", comments);
		request.setAttribute("news", news);
		request.getRequestDispatcher("/showNews.jsp")
				.forward(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
